<?php

require_once 'ConfigEditorHandler.php';

function handle_admin_pass()
{
	global $config;

	$config_file = $config['dir.install'].'etc/config.php';
	$req = new AdminPassConfigEditor(array('source'=>$config_file));
	if ($req->init()) return call_user_func($req->dispatch());
} // end of function handle_check

class AdminPassConfigEditor extends ConfigEditorHandler
{
	public $params = array('admin_password');
	public function loadDefaults ($form)
	{
	} // end of method getFormDefaults
	public function validate ($form)
	{
		if ($form->fields['admin_password']->old_value !== 
			md5($form->fields['admin_password']->old_value_check.$this->cfg->getParam('project_key'))) {
				return 'Старый пароль?';
			}
	} // end of method validate
	public function save ($env)
	{
		$env['admin_password'] = md5($env['admin_password'].$this->cfg->getParam('project_key'));
		return parent::save($env);
	} // end of method save
}

